package org.littlesun.management.jface.fieldassist;

import org.eclipse.jface.fieldassist.IContentProposalListener;
import org.eclipse.jface.fieldassist.IControlContentAdapter;
//import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;
import org.eclipse.swt.widgets.Control;

//import org.eclipse.jface.fieldassist.ContentProposalAdapter;

public class AutoCompleteField {

	private SimpleContentProposalProvider proposalProvider;
	private ContentProposalAdapter adapter;

	public AutoCompleteField(Control control,
			IControlContentAdapter controlContentAdapter, String[] proposals) {
		proposalProvider = new SimpleContentProposalProvider(proposals);
		proposalProvider.setFiltering(true);
		adapter = new ContentProposalAdapter(control, controlContentAdapter,
				proposalProvider, null, null);
		adapter.setPropagateKeys(true);
		adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
	}

	public void setProposals(String[] proposals) {
		proposalProvider.setProposals(proposals);
	}

	public void openProposalPopup() {
		adapter.openProposalPopup();
	}

	public void closeProposalPopup() {
		adapter.closeProposalPopup();
	}
	
	public void addContentProposalListener(IContentProposalListener listener) {
		adapter.addContentProposalListener(listener);
	}

}
